package com.gh.cloud.commons.core.entity.query;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author: guohao
 * @date: 2021-02-18 10:17
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public abstract class BasePageQuery extends BaseQuery {
    private static final long serialVersionUID = -3508259382936906603L;

    @ApiModelProperty(value = "开始查询位置")
    private Integer start;
    @ApiModelProperty(value = "结束查询位置")
    private Integer end;

    @ApiModelProperty(value = "页码")
    private Integer page;

    @ApiModelProperty(value = "每页条数,默认10")
    private Integer limit = 10;

    @ApiModelProperty(value = "商户ID")
    private String tenantId;

    private Boolean isSuperAdmin = false;

    @Override
    public void check() {
        initStart();
        doCheck();
    }

    private void initStart() {
        if (start == null && page != null && limit != null) {
            start = (page - 1) * limit;
            end = start + limit;
        }
    }

    protected abstract void doCheck();
}
